package main.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import main.dao.RegisterDB;
import main.view.Main;
import java.io.IOException;
import java.sql.SQLException;

public class UserRegister {
    private String inputIDcard;
    private String inputUsername;
    private String inputPassword;
    private String inputGrade;
    private String inputCollege;

    @FXML
    private TextField idcard;

    @FXML
    private TextField username;

    @FXML
    private PasswordField password;

    @FXML
    private TextField grade;

    @FXML
    private TextField college;

    @FXML
    private Button register;

    @FXML
    void inputGrade(KeyEvent event) {
        System.out.println(grade.getText());
    }

    @FXML
    void inputIDcard(KeyEvent event) {
        System.out.println(idcard.getText());
    }
    @FXML
    void inputPassword(KeyEvent event) {
        System.out.println(password.getText());
    }
    @FXML
    void inputUsername(KeyEvent event) {
        System.out.println(username.getText());
    }

    @FXML
    void inputCollege(KeyEvent event) {
        System.out.println(college.getText());
    }

    @FXML
    void userRegister(ActionEvent event) throws IOException, SQLException {
        this.inputIDcard = this.idcard.getText();
        this.inputPassword = this.password.getText();
        this.inputUsername = this.username.getText();
        this.inputGrade = this.grade.getText();
        this.inputCollege = this.college.getText();

        new RegisterDB().register(this.inputIDcard,this.inputPassword,this.inputUsername,this.inputGrade,this.inputCollege);
        new Main().initLogin();

    }
}
